package com.ruoyi.common.model.vo;

import com.ruoyi.common.constant.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description: 返回结果
 * @Author: L.Wen
 * @Date: 2024/6/6 10:22
 */
@Data
@ApiModel(description = "返回结果")
public class SimpleRestVo<T> implements Serializable {

    @ApiModelProperty("状态码")
    private int code;
    @ApiModelProperty("消息")
    private String msg;
    @ApiModelProperty("数据")
    private T data;


    public SimpleRestVo() {
    }

    public SimpleRestVo(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 失败返回失败信息
     *
     * @param message
     * @return
     */
    public static SimpleRestVo failedVo(String message) {
        return new SimpleRestVo(HttpStatus.ERROR, message, null);
    }

    /**
     * 失败返回失败信息
     *
     * @param message
     * @return
     */
    public static SimpleRestVo failedVo(int code, String message) {
        return new SimpleRestVo(code, message, null);
    }

    /**
     * 失败返回失败信息
     *
     * @param message
     * @return
     */
    public static <T> SimpleRestVo failedVo(int code, String message, T data) {
        return new SimpleRestVo(code, message, data);
    }

    /**
     * 成功返回信息
     *
     * @return
     */
    public static SimpleRestVo successVo() {
        return successVo(null);
    }

    /**
     * 成功返回信息
     *
     * @param data
     * @return
     */
    public static <T> SimpleRestVo successVo(T data) {
        return new SimpleRestVo(HttpStatus.SUCCESS, "操作成功", data);
    }

    /**
     * 参数校验失败返回信息
     *
     * @param message
     * @return
     */
    public static SimpleRestVo validateFailed(String message) {
        return new SimpleRestVo(HttpStatus.BAD_REQUEST, message, null);
    }

    /**
     * 未登录返回结果
     *
     * @param
     * @return
     */
    public static SimpleRestVo unauthorized() {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, "未授权", null);
    }

    /**
     * 未登录返回结果
     *
     * @param msg
     * @return
     */
    public static SimpleRestVo unauthorized(String msg) {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, msg, null);
    }

    /**
     * 未登录返回结果
     *
     * @param data
     * @return
     */
    public static <T> SimpleRestVo unauthorized(String msg, T data) {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, msg, data);
    }

    /**
     * 未授权返回结果
     *
     * @return
     */
    public static SimpleRestVo forbidden() {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, "未授权", null);
    }

    /**
     * 未授权返回结果
     *
     * @param msg
     * @return
     */
    public static SimpleRestVo forbidden(String msg) {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, msg, null);
    }

    /**
     * 未授权返回结果
     *
     * @param msg
     * @param data
     * @return
     */
    public static <T> SimpleRestVo forbidden(String msg, T data) {
        return new SimpleRestVo(HttpStatus.UNAUTHORIZED, msg, data);
    }
}
